package org.example.backend.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.example.backend.common.Result;
import org.example.backend.dto.StatisticsDTO;
import org.example.backend.service.StatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;

/**
 * 数据统计控制器
 */
@RestController
@RequestMapping("/statistics")
@Api(tags = "数据统计接口")
public class StatisticsController {

    @Autowired
    private StatisticsService statisticsService;

    /**
     * 获取统计数据
     *
     * @return 统计数据
     */
    @GetMapping
    @ApiOperation("获取统计数据")
    public Result<StatisticsDTO> getStatistics() {
        return Result.success(statisticsService.getStatistics());
    }

    /**
     * 获取指定日期范围的统计数据
     *
     * @param startDate 开始日期
     * @param endDate   结束日期
     * @return 统计数据
     */
    @GetMapping("/dateRange")
    @ApiOperation("获取指定日期范围的统计数据")
    public Result<StatisticsDTO> getStatisticsByDateRange(
            @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
            @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate) {
        return Result.success(statisticsService.getStatisticsByDateRange(startDate, endDate));
    }
} 